package com.ebelter.temperature.view;

import android.animation.ObjectAnimator;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.animation.LinearInterpolator;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ebelter.btcomlib.utils.ViewUtils;
import com.ebelter.temperature.R;


/**
 * Created by ZCQ on 2017/12/1
 * 组合控件1 不知道怎么起名字了 还是按序号来吧
 */

public class CombinView2 extends RelativeLayout{
    private TextView temperature_tv;
    private TextView date_tv;
    private TextView warring_tv;


    public CombinView2(Context context) {
        this(context,null);
    }

    public CombinView2(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public CombinView2(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

//        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CombinView1);
//        if (typedArray != null) {
//            title1 = typedArray.getString(R.styleable.CombinView1_title1);
//            hint1 = typedArray.getString(R.styleable.CombinView1_hint1);
//            inputStyle = typedArray.getInt(R.styleable.CombinView1_inputStyle,0);
//
//            typedArray.recycle();
//        }

        initView(getContext());

    }




    private ObjectAnimator ra;


    private void initView(Context context) {
        View view =  View.inflate(context, R.layout.wave_cb_layout, this);//把那个布局当做是自己的孩子
      //  RelativeLayout root = view.findViewById(R.id.cb2_root_rl);
        RelativeLayout yuanhuan_rl = view.findViewById(R.id.wave_waihuan_rl);
        temperature_tv = view.findViewById(R.id.template_tv);
        date_tv = view.findViewById(R.id.date_tv);
        warring_tv = view.findViewById(R.id.warring_tv);

        ra = ObjectAnimator.ofFloat(yuanhuan_rl,"rotation", 0f, 360f);
        ra.setDuration(10000);
        //ra.setRepeatMode(Animation.INFINITE);
        ra.setRepeatCount(-1);
        LinearInterpolator lin = new LinearInterpolator();//设置动画匀速运动
        ra.setInterpolator(lin);


//        ViewGroup.LayoutParams params = root.getLayoutParams();
//        params.width = bg_iv.getMeasuredWidth();
//        params.height = (int) (bg_iv.getMeasuredWidth() * 280.0/342.0);
//        root.setLayoutParams(params);
    }


    public void setTemperature_tv(String str){
        ViewUtils.setTextViewStr(temperature_tv,str);
    }
    public void setDate_tv(String str){
        ViewUtils.setTextViewStr(date_tv,str);
    }
    public void setWarring_tv_tv(String str){
        ViewUtils.setTextViewStr(warring_tv,str);
    }
    public void animation_start(){
        if ( ra!=null)
        {
            ra.start();
        }
    }


    public void animation_pause(){
        if ( ra!=null)ra.pause();
    }

    public void animation_resume(){
        if ( ra!=null)ra.resume();
    }

}
